import numpy as np

arr2_3 = np.arange(0, 3, 0.5).reshape(2, 3)  # 生成2*3的数组
np.savetxt("../file/Pdata2_18.txt", arr2_3)

loadedfile = np.loadtxt("../file/Pdata2_18.txt")
print(loadedfile)  # 返回浮点型数组

# 保存为整型数组, 逗号分隔
np.savetxt("../file/Pdata2_18_2.txt", arr2_3, fmt="%d", delimiter=", ")
loadedfile2 = np.loadtxt("../file/Pdata2_18_2.txt", delimiter=", ")
print(loadedfile2)

# 二进制文件存储
inject_file = np.arange(6).reshape(2, 3)
np.save("../file/Pdata2_23_1.npy", inject_file)
loadfile = np.load("../file/Pdata2_23_1.npy")
other_arr1 = np.arange(6, 12).reshape(2, 3)
other_arr2 = np.sin(other_arr1)
np.savez("../file/Pdata2_23_2.npz", other_arr1, other_arr2)  # 保存多个数组
load_file_from_npz = np.load("../file/Pdata2_23_2.npz")
out_arr_from_npz1 = load_file_from_npz["arr_0"]  # 文件名不能改
out_arr_from_npz2 = load_file_from_npz["arr_1"]
print(out_arr_from_npz1)
print(out_arr_from_npz2)
